<?php

namespace app\controller;

use app\BaseController;
use app\constants\RetCode;
use app\log\LogHandle;
use app\log\UserLog;
use think\facade\Log;

class ApiBaseController extends BaseController
{
    /**
     * @desc 成功json返回
     * @param $msg
     * @param array $data
     * @return \think\response\Json
     */
    public function successReturn($msg, array $data): \think\response\Json
    {
       return $this->returnJson(RetCode::SUCCESS_RET, $msg, $data);
    }

    public function returnJson($ret, $msg, $data): \think\response\Json
    {
        $arr = ['ret' => $ret, 'msg' => $msg, 'data' => $data, 'unique_no' => LogHandle::getUniqueNo()];

        UserLog::Info("返回数据", $arr);

        return json($arr);
    }
}